package com.createthread.p3;

/**
 * @PackageName:com.createthread.p3
 * @ClassName:Test
 * @Description: 测试实现Runnable接口的形式创建线程
 * @Author: zhangxiaoyu
 * @date 2020/11/18 14:35
 */
public class Test {
    public static void main(String[] args){
       //创建runnable接口的实现类对象
        MyRunnable runnable = new MyRunnable();
        //创建线程对象
        Thread thread = new Thread(runnable);
        //开启线程
        thread.start();

        //当前是main线程
        for(int i =1;i<=100;i++){
            System.out.println("main:==="+i);
        }

        //有时候调用Thread(Runnable)构造方法时，实参也会传递匿名内部类对象
        Thread thread2 = new Thread(new Runnable() {
            @Override
            public void run() {
                for(int i=1;i<=100;i++){
                    System.out.println("sub=======:"+i);
                }
            }
        });
        thread2.start();
    }
}
